/**
 * Created by rekey on 13-12-13.
 */
/**
 * Created with JetBrains WebStorm. User: rekey Date: 7/9/13 Time: 23:49 To
 * change this template use File | Settings | File Templates.
 */
var crypto = require('crypto');

function md5(str, isShort) {
    var md5 = crypto.createHash('md5');
    md5.update(str);
    var ret = md5.digest('hex');
    return isShort ? ret.substr(8, 16) : ret;
    
}
function encrypt(str, secret) {
    var cipher = crypto.createCipher('aes192', secret);
    var enc = cipher.update(str, 'utf8', 'hex');
    enc += cipher.final('hex');
    return enc;
}

function decrypt(str, secret) {
    var decipher = crypto.createDecipher('aes192', secret);
    var dec = decipher.update(str, 'hex', 'utf8');
    dec += decipher.final('utf8');
    return dec;
}
module.exports = {
    md5 : md5 ,
    encrypt : encrypt ,
    decrypt : decrypt
};